<?php

    class Ruangan extends CI_Model
    {
        private $roomID;
        private $roomName;
        private $description;
        private $pjRuangan;
        private $parentRoom;

        // Konstruktor
        public function Ruangan_model() {
            parent::Model();
        }

        // Getter dan Setter Biasa
        public function getRoomId() {
            return $this->roomID;
        }

        public function setRoomId($roomID) {
            $this->roomID = $roomID;
        }

        public function getRoomName() {
            return $this->roomName;
        }

        public function setRoomName($roomName) {
            $this->roomName = $roomName;
        }

        public function getDescription() {
            return $this->description;
        }

        public function setDescription($description) {
            if ($description) {
                $this->description = $description;
            } else {
                $this->description = NULL;
            }
        }

        public function getPjRuangan() {
            return $this->pjRuangan;
        }

        public function setPjRuangan($pjRuangan) {
            $this->pjRuangan = $pjRuangan;
        }

        public function getParentRoom() {
            return $this->parentRoom;
        }

        public function setParentRoom($parentRoom) {
            if ($parentRoom) {
                $this->parentRoom = $parentRoom;
            } else {
                $this->parentRoom = NULL;
            }
        }

        // Operasi Data
        public function getAllRuangan()
        {
            $query=$this->db->get('Ruangan');
            return $query->result();
        }

        public function getRuangan($roomID){
            $query = $this->db->query
                    ("
                        SELECT *
                        FROM ruangan
                        WHERE (roomID = '".$roomID."')
                    ");
            return $query->row();
        }

        public function insertRuangan() {
            $data = array(
                'roomID' => $this->roomID,
                'roomName' => $this->roomName,
                'description' => $this->description,
                'pjRuangan' => $this->pjRuangan,
                'parentRoom' => $this->parentRoom
            );
            if (!$data['description']) $data['description'] = NULL;
            if (!$data['parentRoom']) $data['parentRoom'] = NULL;
            $this->db->insert('ruangan',$data);
        }

        public function changeRuangan($ruangan) {
            if (!$ruangan['description'])
                $ruangan['description'] = NULL;
            if (!$ruangan['parentRoom'])
                $ruangan['parentRoom'] = NULL;
            $this->db->where('roomID', $this->roomID);
            $this->db->update('ruangan', $ruangan);
        }

        public function deleteRuangan() {
            $this->db->delete('ruangan', array('roomID' => $this->roomID));
        }

        /* By Arian Ichsan . Untuk keperluan melakukan konfirmasi reservasi
         * Mengambil semua ruangan yang merupakan tanggung jawab $userID
         */
        public function getRuanganByPJRuangan($userID)
        {
            $query = $this->db->query
                    ("
                        SELECT *
                        FROM ruangan
                        WHERE (pjRuangan = '".$userID."')
                    ");
            return $query->result();
        }
    }
?>
